package com.iheima.branch;

import java.util.Random;
import java.util.Scanner;

public class test {
    public static void main(String[] args) {
        test1();
    }
    //猜数字游戏-也可以while用true，循环里面开始就输入然后判断break
    public static void test1(){
        int sub=(int)(Math.random()*100+1);
        System.out.println("请输入一个数字");
        Scanner sc=new Scanner(System.in);
        int num=sc.nextInt();

        while(num!=sub){
            if(num<sub){System.out.println("输入的数字小了"); num=sc.nextInt();}
            else if(num>sub){System.out.println("输入的数字大了"); num=sc.nextInt();}
            else break;
        }
        System.out.println("对了");
    }
}
